<template>
<div class="vue-box sbot sbot-fluid">
  <!-- 参数栏 -->
  <div class="c-panel">
    <el-form :inline="true">
      <!-- 表单 -->
      <sa-item v-model="m.name" type="text" name="广告位" br />
      <sa-item v-model="m.code" type="text" name="识别码" br />
      <sa-item v-model="m.location" type="text" name="所在视图" br />
      <sa-item v-model="m.sid" type="enum" jtype="3" :jv="dims.SD" name="所属服务" br />
      <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
      <sa-item v-model="m.note" type="text" name="描述" br />
      <sa-item v-model="m.sort" type="num" name="序号" br />
      <sa-item name="" br class="s-ok">
        <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
      </sa-item>
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  name: 'ads-space-update',
  props: {
    param: Object
  },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims,
    }
  },
  created: function () {},
  watch: {},
  methods: {
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        code: this.param.code,
        location: this.param.location,
        sid: this.param.sid,
        status: this.param.status,
        note: this.param.note,
        sort: this.param.sort
      }
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.name, '请输入广告位');
      sa.checkNull(m.code, '请输入编码码');
      sa.checkNull(m.status, '请确认是否启用');

      // 将标准转换未字符串
      if (this.selectTags) {
        m.tags = JSON.stringify(this.selectTags)
      }

      // 添加
      sa.ajax('/ads/space/update', m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), {
        type: 'post'
      });
    },
  }
}
</script>

<style scoped></style>
